package spec;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;

public class TransFormSpecTemplate {
    public static void main(String[] args) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        URL url = TransFormSpecTemplate.class.getClassLoader().getResource("spec/data.json");

        List<SpecTemplate> templates = mapper.readValue(url, new TypeReference<List<SpecTemplate>>() {
        });

        File base = new File("templates");
        if (!base.exists()) {
            base.mkdir();
        }

        templates.forEach(template -> {
            System.out.println(template.itemId);
            try {
                mapper.writeValue(new File(base, template.itemId + ".json"), template);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

    }
}
